Laravel-数据库映射错误 could not find driver

问题

今天在 Laravel 框架中, 初始化数据库映射的过程中即“php artisan migrate”中出现Illuminate\Database\QueryException : could not find driver (SQL: select * from information_schema.tables where table_schema = test and table_name = migrations and table_type = 'BASE TABLE')错误,全称为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 Illuminate\Database\QueryException  : could not find driver (SQL: select * from information_schema.tables where table_schema = test and table_name = migrations and table_type = 'BASE TABLE')

at /home/kunlun/Development/Web/ZhongShan/Zhongshan_computer_port_security_joint_audit_platform/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669
665| // If an exception occurs when attempting to run a query, we'll format the error
666| // message to include the bindings with SQL, which will make this exception a
667| // lot more helpful to the developer instead of just the database's errors.
668| catch (Exception $e) {
> 669| throw new QueryException(
670| $query, $this->prepareBindings($bindings), $e
671| );
672| }
673|

Exception trace:

1 PDOException::("could not find driver")
/home/kunlun/Development/Web/ZhongShan/Zhongshan_computer_port_security_joint_audit_platform/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

2 PDO::__construct()
/home/kunlun/Development/Web/ZhongShan/Zhongshan_computer_port_security_joint_audit_platform/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

Please use the argument -v to see more details.

解决

该方法的解决方案就是通过编辑php.ini文件进行解决:

  1. find / -name php.init
  2. vim /etc/php/php.ini
  3. ;extension=pdo_mysql 将前面的 “;” 去掉后保存在此运行 php artisan migrate即可解决此问题

本文使用《江雪分析公开知识存储库知识共享许可证》进行发布